﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Destory : MonoBehaviour {
    // Start is called before the first frame update
    public float createTime;
    public float currentTime;
    public int index = 0;
    void Start() {
        createTime = Time.time;
        index = 0;
    }

    // Update is called once per frame
    void Update() {
        currentTime = Time.time;
        if (currentTime - createTime >= 10) {
            Destroy(GameObject.Find(this.name));
        }
    }

    // 碰撞开始
     void OnCollisionEnter(Collision collision) {
        // 销毁当前游戏物体
        if ( collision.transform.tag == "Ground") {
            GameObject temp = Instantiate((GameObject)Resources.Load("Prefabs/Plant"));//加载预制体资源
            temp.transform.position = new Vector3(this.transform.position.x, this.transform.position.y+4, this.transform.position.z);//植物的位置置为当前玩家的位置
            temp.name = "Plant" + index;//球体的名称为迭代加1
            index++;

            Debug.Log(name + "销毁");
            Destroy(GameObject.Find(name));
            //Destroy(this);
        }
        
    }

    // 碰撞结束
    void OnCollisionExit(Collision collision) {
    }
    // 碰撞持续中
    void OnCollisionStay(Collision collision) {
        
    }
}
